import React from "react";


class DigitalClock extends React.Component {
    constructor(props){
        super(props)
        this.state= {
            data:new Date()
        }
    }
    componentDidMount(){ //创建时
        this.timer = setInterval(()=>{
            this.setState({
                data: new Date()
            })
        },5000)
    }
    componentDidUpdate(currentProps,currentState){ //更新时currentProps 传入的值
        console.log(currentState)
    }
    componentWillUnmount(){ //清除时
        clearInterval(this.timer)
    }
    render(){
        return(
            <div className="digital-clock-component jumbotron">
                <h1> {this.state.data.toLocaleTimeString()}</h1>
            </div>
        )
    }
}

export default DigitalClock
